package com.aabbc.trading;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

/**
 * UserServiceApplication
 *
 * @author: <a href="mailto:chenfenghai@oristartech.com">chenfenghai</a>
 * @version: 1.0
 * @date: 2019-11-01 13:40
 */
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
@EnableFeignClients(basePackages = {"com.aabbc.user.facade", "com.aabbc.order.facade"})
@SpringBootApplication(scanBasePackages = {"com.aabbc.trading", "com.aabbc.user"}, exclude = DataSourceAutoConfiguration.class)
public class TradingServiceApplicationStarter {

    public static void main(String[] args) {
        SpringApplication.run(TradingServiceApplicationStarter.class, args);
    }

    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean =new ServletRegistrationBean<>();
        registrationBean.setServlet(new HystrixMetricsStreamServlet());
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}
